/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package co.edu.univalle.persistencia;

import co.edu.univalle.modelo.Categorias;
import co.edu.univalle.modelo.Clientes;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author valentina
 */
@Stateless
public class CategoriasDAO implements ICategoriasDAO {
    
    @PersistenceContext
    private EntityManager entityManager;

    @Override
    public void registrar(Categorias categoria) {
        
  
         try{
         entityManager.persist(categoria);
     }
     catch (RuntimeException e){
     throw e;
    }
  }


    @Override
    public void modificar(Categorias categoria) {
        
            try{
         entityManager.merge(categoria);
     }
     catch (RuntimeException e){
     throw e;
     }
    }

    
    @Override
    public void eliminar(Categorias categoria) {
                try{
         entityManager.remove(categoria);
     }
     catch (RuntimeException e){
     throw e;
     }
    }

    @Override
    public List<Categorias> consultar() {
               
             try{
                String jpql = "SELECT c FROM categorias c";
                Query query = entityManager.createQuery(jpql);
                return query.getResultList();
         
     }
     catch (RuntimeException e){
     throw e;
}
    }

    

    @Override
    public Categorias consultarPorId(Integer idcategoria) {
                   try{
                    return entityManager.find(Categorias.class, idcategoria);
     }
                
     catch (RuntimeException e){
     throw e;
       
        }
    }
}
